# This Dockerfile was generated from templates/Dockerfile.j2
{% if local_artifacts == 'false' -%}
{%   set url_root = 'https://artifacts.elastic.co/downloads/logstash' -%}
{% else -%}
{%   set url_root = 'http://localhost:8000' -%}
{% endif -%}

{% if image_flavor == 'oss' -%}
  {% set tarball = 'logstash-oss-%s.tar.gz' % elastic_version -%}
  {% set license = 'Apache 2.0' -%}
{% else -%}
  {% set tarball = 'logstash-%s.tar.gz' % elastic_version -%}
  {% set license = 'Elastic License' -%}
{% endif -%}


FROM centos:7

# Install Java and the "which" command, which is needed by Logstash's shell
# scripts.
RUN yum update -y && yum install -y java-11-openjdk-devel which && \
    yum clean all

# Provide a non-root user to run the process.
RUN groupadd --gid 1000 logstash && \
    adduser --uid 1000 --gid 1000 \
      --home-dir /usr/share/logstash --no-create-home \
      logstash

# Add Logstash itself.
RUN curl -Lo - {{ url_root }}/{{ tarball }} | \
    tar zxf - -C /usr/share && \
    mv /usr/share/logstash-{{ elastic_version }} /usr/share/logstash && \
    chown --recursive logstash:logstash /usr/share/logstash/ && \
    chown -R logstash:root /usr/share/logstash && \
    chmod -R g=u /usr/share/logstash && \
    find /usr/share/logstash -type d -exec chmod g+s {} \; && \
    ln -s /usr/share/logstash /opt/logstash

WORKDIR /usr/share/logstash

ENV ELASTIC_CONTAINER true
ENV PATH=/usr/share/logstash/bin:$PATH

# Provide a minimal configuration, so that simple invocations will provide
# a good experience.
ADD config/pipelines.yml config/pipelines.yml
ADD config/logstash-{{ image_flavor }}.yml config/logstash.yml
ADD config/log4j2.properties config/
ADD pipeline/default.conf pipeline/logstash.conf
RUN chown --recursive logstash:root config/ pipeline/

# Ensure Logstash gets a UTF-8 locale by default.
ENV LANG='en_US.UTF-8' LC_ALL='en_US.UTF-8'

# Place the startup wrapper script.
ADD bin/docker-entrypoint /usr/local/bin/
RUN chmod 0755 /usr/local/bin/docker-entrypoint

USER 1000

ADD env2yaml/env2yaml /usr/local/bin/

EXPOSE 9600 5044


LABEL  org.label-schema.schema-version="1.0" \
  org.label-schema.vendor="Elastic" \
  org.opencontainers.image.vendor="Elastic" \
  org.label-schema.name="logstash" \
  org.opencontainers.image.title="logstash" \
  org.label-schema.version="{{ elastic_version }}" \
  org.opencontainers.image.version="{{ elastic_version }}" \
  org.label-schema.url="https://www.elastic.co/products/logstash" \
  org.label-schema.vcs-url="https://github.com/elastic/logstash" \
  license="{{ license }}" \
  org.label-schema.license="{{ license }}" \
  org.opencontainers.image.licenses="{{ license }}" \
  org.label-schema.build-date={{ created_date }} \
  org.opencontainers.image.created={{ created_date }}


ENTRYPOINT ["/usr/local/bin/docker-entrypoint"]
